package cn.edu.sctu.sctu_lysd.utils;

import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.LinearInterpolator;
import android.view.animation.RotateAnimation;

/**
 * Created by 鑫爷您慢点 on 2016/9/13.
 */
public class AnimationHelper {
    private static AnimationHelper animationHelper = null;

    private AnimationHelper() {
    }

    /**
     * 单例
     * @return
     */
    public static AnimationHelper getInstance(){
        if (animationHelper == null){
            animationHelper = new AnimationHelper();
        }
        return animationHelper;
    }

    /**
     *旋转动画
     * @param from
     * @param to
     * @param duration
     * @param repeatCount
     * @return
     */
    public RotateAnimation getRotateAnimation(float from, float to, long duration, int repeatCount) {
        RotateAnimation rotateAnimation = new RotateAnimation(from,
                to,
                Animation.RELATIVE_TO_SELF,
                0.5f,
                Animation.RELATIVE_TO_SELF,
                0.5f);
        rotateAnimation.setDuration(duration);
        rotateAnimation.setFillAfter(true);
        rotateAnimation.setRepeatCount(repeatCount);
        rotateAnimation.setInterpolator(new LinearInterpolator());
        return rotateAnimation;
    }

    /**
     *渐变动画
     * @param from
     * @param to
     * @param duration
     * @return
     */
    public AlphaAnimation getAlphaAnimation(float from, float to, long duration) {
        AlphaAnimation alphaAnimation = new AlphaAnimation(from,to);
        alphaAnimation.setDuration(duration);
        alphaAnimation.setFillAfter(true);
        return alphaAnimation;
    }
}
